FUNCTION(CREATE_TESTS)
	SET(TEST_FILE ${PROJECT_SOURCE_DIR}/tests.py)
	STRING(REPLACE "/" "\\" TEST_FILE "${TEST_FILE}")
	STRING(REPLACE "/" "\\" INTERPRETER "${PYTHON_EXECUTABLE}")
	STRING(REPLACE "/" "\\" WORK_DIR "${ROOT_DIR}/test/lib")
	STRING(REPLACE "/" "\\" PROTOTYPE_TESTER "${PROTOTYPE_TESTER}")
	EXECUTE_PROCESS(COMMAND ${INTERPRETER} ${TEST_FILE} --list
					OUTPUT_VARIABLE TEST_LIST
					RESULT_VARIABLE HAD_ERROR
					WORKING_DIRECTORY ${WORK_DIR}
				   )
	IF(HAD_ERROR)
	    MESSAGE(FATAL_ERROR "Failed create tests! Please check ${TEST_FILE}")
	ENDIF()

	STRING(REPLACE "\n" "" TEST_LIST "${TEST_LIST}")

	IF("${TEST_LIST}" STREQUAL "")
		RETURN()
	ENDIF()

	LIST(LENGTH TEST_LIST LEN)
	MATH(EXPR LEN "${LEN}-1")
	FOREACH(TEST_NO RANGE ${LEN})
		LIST(GET TEST_LIST ${TEST_NO} TEST_NAME)
		IF ("${PROGRAM_TO_TEST}" STREQUAL "")
		    SET(PROGRAM_TO_TEST $<TARGET_FILE:${PROJECT_EXECUTABLE}>)
		ENDIF()
        ADD_TEST(NAME "${PROJECT_NAME}_${TEST_NAME}_${TEST_NO}"
        		 COMMAND ${CMAKE_COMMAND}
					-DINTERPRETER=${INTERPRETER}
        		 		-DTEST_FILE=${TEST_FILE}
        		 		-DTEST_NO=${TEST_NO}
        		 		-DTEST_NAME=${PROJECT_NAME}_${TEST_NAME}_${TEST_NO}
					-DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
					-DTESTER=$<TARGET_FILE:sp>
					-DATESTER=${PROTOTYPE_TESTER}
 					-DPROGRAM_TO_TEST=${PROGRAM_TO_TEST}
 					-DBUILD_DIR=${BUILD_DIR}
 					-DWORK_DIR=${WORK_DIR}
	    				-P ${ROOT_DIR}/test/lib/runtest.cmake
 				)
	ENDFOREACH(TEST_NO)
ENDFUNCTION(CREATE_TESTS)
FUNCTION(NEW_TEST)
IF ("${TEST_SUBNAME}" STREQUAL "")
	SET(TEST_NAME "${PROJECT_NAME}_${TEST_NO}")
ELSE()
	SET(TEST_NAME "${PROJECT_NAME}_${TEST_SUBNAME}_${TEST_NO}")
ENDIF()
add_test(NAME ${TEST_NAME}
    COMMAND ${CMAKE_COMMAND}
    -DTEST_PROG=${TEST_PROG}
    -DTEST_NAME=${TEST_NAME}
    -DPROGRAM_TO_TEST=${PROGRAM_TO_TEST}
    -DPROGRAM_ARGUMENTS=${PROGRAM_ARGUMENTS}
    -DMEMORY_LIMIT=${MEMORY_LIMIT}
    -DWRITE_LIMIT=${WRITE_LIMIT}
    -DTIME_LIMIT=${TIME_LIMIT}
    -DUSER_TIME_LIMIT=${USER_TIME_LIMIT}
    -DLOAD_RATIO=${LOAD_RATIO_LIMIT}
    -DSOURCEDIR=${PROJECT_SOURCE_DIR}
    -DBUILD_DIR=${BUILD_DIR}
    -DEXPECTED_PROCESS_STATE=${PROCESS_STATE}
    -DEXPECTED_TERMINATE_REASON=${TERMINATE_REASON}
    -DEXPECTED_EXCEPTION=${EXCEPTION}
    -DWORKING_DIR=${WORKING_DIR}
    -P ${ROOT_DIR}/test/lib/runtest.cmake)
MATH(EXPR X "${TEST_NO}+1")
SET(TEST_NO ${X} CACHE INTERNAL "Test number" FORCE)
ENDFUNCTION(NEW_TEST)